hysop.tools.misc module

Some utilities to deal with workspaces, slices and other python objects

  • Utils : some utilities to handle slices in hysop.

  • WorkSpaceTools to deal with operators’ local work spaces, see work_spaces.

class hysop.tools.misc.Utils[source]

Bases: object

tools to handle array and slices.

static argsort(seq)[source]
static array_to_dict(inarray)[source]

convert an array into a dictionnary, keys being the column numbers in array and values the content of each corresponding column transformed into a list of slices like this: column = [1, 4, 2, 6, …] —> [slice(1, 4), slice(2, 6), …]

static intersect_slices(sl1, sl2)[source]

Intersection of two lists of slices

Parameters:
  • sl1 (a list of slices)

  • sl2 (a list of slices)

  • Return – guess what … a list of slices such that: result[i] = intersection between sl1[i] and sl2[i]

static is_on_proc(sl)[source]

True if sl represent a non empty set of indices.

static upper_pow2(x)[source]
class hysop.tools.misc.WorkSpaceTools[source]

Bases: object

Tools to deal with internal work arrays for operators

static allocate_common_workspaces(work_properties)[source]

Allocate a list of common workspaces according to some given properties.

Parameters:

work_properties (list of lists of tuples) – properties of workspaces. Each component of this list must be the return value of a get_work_properties function (for instance from an operator)

Returns:

work – workspaces fitting with properties requirements.

Return type:

list of numpy arrays

Example

# op1, op2 some predifined operators op1.discretize() op2.discretize() wk_prop = [] wk_prop.append(op1.get_work_properties()[‘rwork’]) wk_prop.append(op2.get_work_properties()[‘rwork’]) work = Utils.find_common_workspace(wk_prop)

op1.setup(rwork=work) op2.setup(rwork=work) # work is a common internal list of workspaces that can be used by both # operators.

static check_work_array(lwork, subshape, work=None, data_type=<class 'numpy.float64'>)[source]

Check properties of existing working array or allocate some new buffers complient with some properties.

Parameters:
  • lwork (int) – required number of working arrays

  • subshape (list of tuples of int) – required shape for work array subshape[i] == expected shape for work[i]

  • work (list of numpy arrays)

  • data_type (either HYSOP_REAL or HYSOP_INTEGER)

Notes

work arrays are 1D arrays of size prod(subshape) that are ‘reshaped’ according to the specific needs of each operator. That means that one memory location (the 1D array) may be shared between several operators thanks to the numpy reshape function.

static find_common_workspace(operators, array_type='rwork')[source]
hysop.tools.misc.args2kargs(func, args)[source]
hysop.tools.misc.compute_nbytes(shape, dtype)[source]
hysop.tools.misc.get_argnames(func)[source]

returns arguments name and possible varargs.

hysop.tools.misc.get_default_args(func)[source]

returns a dictionary of arg_name:default_values for the input function.

hysop.tools.misc.getargspec(func)[source]
hysop.tools.misc.kargs2args(func, kargs, remove=[])[source]
hysop.tools.misc.next_pow2(x)[source]
hysop.tools.misc.previous_pow2(x)[source]
hysop.tools.misc.prod(values)[source]

Like sum but for products (of integers).

hysop.tools.misc.upper_pow2(x)[source]
hysop.tools.misc.upper_pow2_or_3(x)[source]